<template>
  <div>
    <x-card v-if="hasPerm('gardenhouse:page')">
      <div
        slot="content"
        class="table-page-search-wrapper"
      >
        <a-form layout="inline">
          <a-row :gutter="20">
            <a-col
              :md="7"
              :sm="24"
            >
              <a-form-item label="班级">
                <a-input
                  v-model="queryParam.ClassId"
                  allow-clear
                  placeholder="请输入班级名称"
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="7"
              :sm="24"
            >
              <a-form-item label="标题">
                <a-input
                  v-model="queryParam.Title"
                  allow-clear
                  placeholder="请输入标题名称"
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="7"
              :sm="24"
            >
              <a-button
                type="primary"
                @click="$refs.table.refresh(true)"
              >查询</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </x-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :rowKey="(record) => record.id"
      >
        <span
          slot="action"
          slot-scope="text, record"
        >
          <a
            v-if="hasPerm('gardenhouse:add')"
          >预览</a>
          <a-divider
            type="vertical"
            v-if="hasPerm('sysclasses:edit') & hasPerm('sysclasses:delete')"
          />
          <a
            type="danger"
            v-if="hasPerm('gardenhouse:delete')"
          >修改</a>
          <a-divider
            type="vertical"
            v-if="hasPerm('sysclasses:edit') & hasPerm('sysclasses:delete')"
          />
          <a-popconfirm
            v-if="hasPerm('sysclasses:delete')"
            placement="topRight"
            title="确认删除？"
            @confirm="() => singleDelete(record)"
          >
            <a>删除</a>
          </a-popconfirm></span>
      </s-table>
    </a-card>
  </div>
</template>

<script>
import {parentChildTasksList,tasksDelete} from '@/api/modular/garden/parentchildtasks'
import { STable, XCard, XDown } from "@/components";
export default {
  components: {
    XDown,
    XCard,
    STable,
  },
  data() {
    return {
       // 查询参数
      queryParam: {
        ClassId: undefined,
        Title:undefined
      },
      // 表头
      columns: [
        {
          title: "标题",
          dataIndex: "title",
        },
        {
          title: "班级",
          dataIndex: "className",
        },
        {
          title: "发布人",
          dataIndex: "createdUser",
        },
        {
          title: "状态",
          dataIndex: "stateStr",
        },
        {
          title: "已参与人数",
          dataIndex: "count",
        },
        {
          title: "发布时间",
          dataIndex: "startDate",
        },
        {
          title: "操作",
          scopedSlots: { customRender: "action" },
          width: "150px",
        },
      ],
      selectedRowKeys: [],
      selectedRows: [],
      loadData: (parameter) => {
        return parentChildTasksList(Object.assign(parameter, this.queryParam)).then((res) => {
         if(res.data.rows.length){
          console.log(res.data);
            return res.data
          }
        })
      },
    };
  },
  methods: {
    /**
     * 单个删除
     */
    singleDelete(record) {
      const param = [{ id: record.id }];
      this.tasksDelete(param);
    },
    /**
     * 删除
     */
    tasksDelete(param) {
      tasksDelete(param)
        .then((res) => {
          if (res.success) {
            this.$message.success("删除成功");
            this.$refs.table.clearRefreshSelected();
          } else {
            this.$message.error("删除失败：" + res.message);
          }
        })
        .catch((err) => {
          this.$message.error("删除错误：" + err.message);
        });
    },
    changeStatus(record) {
      console.log(record);
    },
    handleOk() {
      this.$refs.table.refresh();
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
    },
  },
};
</script>

<style></style>
